import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.TimerTask;
import java.util.Vector;

public class Radio extends TimerTask
{
	
	DatagramSocket socket;
	InetAddress IAddress;
	int port;
	int count;

	
	private Vector<String> sampleData = new Vector<String>();
	
	public Radio(DatagramSocket welcomeSocket, InetAddress IAddress, int port)
	{
		socket = welcomeSocket;
		this.IAddress = IAddress;
		this.port = port;
		count = 0;
		
		sampleData.add("One");
		sampleData.add("Two Two");
		sampleData.add("Three Three Three");
		sampleData.add("Four Four Four Four");
		sampleData.add("Five Five Five Five Five");
		sampleData.add("Six Six Six Six Six Six");
		sampleData.add("Seven Seven Seven Seven Seven Seven Seven");
		sampleData.add("Eight Eight Eight Eight Eight Eight Eight Eight");
		sampleData.add("Nine Nine Nine Nine Nine Nine Nine Nine Nine");
		sampleData.add("Ten Ten Ten Ten Ten Ten Ten Ten Ten Ten");
	}
	
	public String getSample()
	{
		return sampleData.elementAt(count++%10);
	}
	boolean b=true;
	public void run() 
	{
		try {
			byte[] sendData = new byte[100];
			String sample = getSample();
			System.out.println("Sending Sample: "+sample);
			RadioPacket p = new RadioPacket(100);
			p.setPacketType("DAT".getBytes());
			p.setPacketId((""+count).getBytes());
			p.setData(sample.getBytes());
			sendData = p.getBytes();
			DatagramPacket datagramPacket = new DatagramPacket(sendData, sendData.length, IAddress, port);
			socket.send(datagramPacket);
			b=true;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}